package com.mvprxjavartrofit.network;


import com.mvprxjavartrofit.network.api.LoginApi;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator
 * At 2016/10/19/11:05/2016
 * Project test
 */
public class HttpUtil {
    private static HttpUtil httpUtil;
    private static final String URL = "http://www.fxh1106.com";
    private static final int DEFAULT_TIMEOUT = 5;

    private LoginApi loginApi;

    public static HttpUtil getInstance(){
        if(httpUtil == null){
            httpUtil = new HttpUtil();
        }
        return httpUtil;
    }

    private HttpUtil(){
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);

        Retrofit retrofit = new Retrofit.Builder()
                .client(builder.build())
                .baseUrl(URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();

        loginApi = retrofit.create(LoginApi.class);
    }

    public LoginApi getLoginApi() {
        return loginApi;
    }

    public void setLoginApi(LoginApi loginApi) {
        this.loginApi = loginApi;
    }
}
